﻿using Service.Domain.Conventions;
using Service.Domain.Entities;
using Service.Domain.Entities.User;
using Service.Domain.Interfaces;
using Service.Domain.Interfaces.Repositories;
using Service.Domain.Shared.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Service.Repository.User
{
    public class UserRepository : IUserRepository
    {
        readonly IDbContext db;
        public UserRepository(IDbContext db)
        {
            this.db = db;
        }

        public void Add(UserInfo obj)
        {
            throw new NotImplementedException();
        }

        public async Task<UserInfo> FindByUserNameOrMobileOrEmail(string name, string password)
        {
            string sql = @"SELECT U.id, U.username, U.email, U.mobile, U.mobileVerify, U.emailVerify
                FROM Users AS `U`
                WHERE (username = @Username OR email = @Username OR mobile = @Username) AND `password` = @Password AND `status` = @Status";
            var user = await this.db.QueryFirstOrDefaultAsync<UserInfo>(sql, new { Username = name, Password = password, Status = 1 });
            return user;
        }

        public IQueryable<UserInfo> GetAll(IConvention<UserInfo> condition)
        {
            throw new NotImplementedException();
        }

        public UserInfo GetById(int id)
        {
            throw new NotImplementedException();
        }

        public void Remove(int id)
        {
            throw new NotImplementedException();
        }

        public int SaveChanges()
        {
            throw new NotImplementedException();
        }

        public void Update(UserInfo obj)
        {
            throw new NotImplementedException();
        }
    }
}
